package dao

import (
	"go-weixin/app/usercenter/model"
	"go-weixin/common/chendb"
	// "go-weixin/common/utils"
)

type TableDao struct {
	engine chendb.ChenDb
}

func NewTableDao(engine chendb.ChenDb) *TableDao {
	return &TableDao{
		engine: engine,
	}
}
func (t TableDao) TableAdd(name string, url string, method int64, table *model.TablesModel) (int64, error) {
	table.Name = name
	table.Url = url
	table.Method = method
	return t.engine.Insert(table)
}
func (t TableDao) TableExistByUrl(url string) (bool, error) {
	return t.engine.Exist(&model.TablesModel{
		Url: url,
	})
}

func (t TableDao) TableList(limit int64, offset int64, tableList *[]model.TablesModel) error {
	return t.engine.Limit(int(limit), int(offset)).Find(tableList)
}

func (t TableDao) TableExistById(id int64) (bool, error) {
	return t.engine.Exist(&model.TablesModel{Id: id})
}

func (t TableDao) TableUpdate(id int64, name string, url string, method int64) (int64, error) {
	return t.engine.ID(id).Update(&model.TablesModel{
		Name:   name,
		Url:    url,
		Method: method,
	})
}
